package com.leo.script;

import lombok.SneakyThrows;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleBindings;
import javax.script.SimpleScriptContext;

public class PythonUtils {

    @SneakyThrows
    public static void main(String[] args) {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
        SimpleScriptContext context = new SimpleScriptContext();
        context.setWriter(new Slf4jInfoWriter());
        context.setErrorWriter(new Slf4jErrorWriter());
        engine.setContext(context);

        SimpleBindings bindings = new SimpleBindings();
        bindings.put("a", 0.1);
        bindings.put("b", 0.2);
        Object result = engine.eval("a + b", bindings);
        System.out.println(result);
    }
}
